X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/2af83e98005a14c439b360a5b9ac636f594d9f0c..4fc09567c557a1110180940cca40fd7144921026:/Super%20Polarity/Actors/StandardShip.cs diff --git a/Super Polarity/Actors/StandardShip.cs b/Super Polarity/Actors/StandardShip.cs deleted file mode 100644 index 50a671a..0000000 --- a/Super Polarity/Actors/StandardShip.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Content; -using System.Security.Cryptography; - -namespace SuperPolarity -{ - class StandardShip : Ship - { - - protected int ChangeRate; - protected int CurrentTime; - protected int AngleChangeProbability; - protected int BouncePadding; - protected float RotationFactor; - protected Random Random; - protected bool AddingAngle; - - public StandardShip(Game newGame) : base(newGame) {} - - public override void Initialize(Texture2D texture, Vector2 position) - { - base.Initialize(texture, position); - - var cryptoResult = new byte[4]; - new RNGCryptoServiceProvider().GetBytes(cryptoResult); - - ChangeRate = 50; - AngleChangeProbability = 50; - BouncePadding = 0; - MaxVelocity = 1; - CurrentTime = 0; - RotationFactor = (float) (3 * Math.PI / 180); - Random = new Random(BitConverter.ToInt32(cryptoResult, 0)); - AddingAngle = true; - } - - public override void Magnetize(Ship ship, float distance, float angle) - { - if (ship.GetType() == typeof(MainShip)) { - base.Magnetize(ship, distance, angle); - } - } - - public override void Update(GameTime gameTime) - { - CurrentTime += gameTime.ElapsedGameTime.Milliseconds; - if (!Magnetizing) - { - AutoMove(); - BounceBack(); - } - ChangeAngle(); - Position += Velocity; - Magnetizing = false; - } - - protected void AutoMove() - { - float newAngle = Angle; - - if (CurrentTime < ChangeRate) - { - return; - } - - if (Random.Next(AngleChangeProbability) == 2) - { - AddingAngle = !AddingAngle; - } - - CurrentTime = 0; - - if (AddingAngle) - { - newAngle += (float) ( Random.NextDouble() * RotationFactor); - } - else - { - newAngle -= (float) (Random.NextDouble() * RotationFactor); - } - - Velocity.X = (float) (MaxVelocity * Math.Cos(newAngle)); - Velocity.Y = (float) (MaxVelocity * Math.Sin(newAngle)); - } - - protected void BounceBack() - { - if (Position.X + Width < -BouncePadding && Velocity.X < 0) - { - Velocity.X = -Velocity.X; - } - - if (Position.Y + Height < -BouncePadding && Velocity.Y < 0) - { - Velocity.Y = -Velocity.Y; - } - - if (Position.X > game.GraphicsDevice.Viewport.Width + BouncePadding && Velocity.X > 0) - { - Velocity.X = -Velocity.X; - } - - if (Position.Y > game.GraphicsDevice.Viewport.Height + BouncePadding && Velocity.Y > 0) - { - Velocity.Y = -Velocity.Y; - } - } - } -}